/*
 * @Date: 2023-04-26 16:06:45
 * @Description:全局状态树
 * @LastEditors: hujingyang
 * @Author: hujingyang
 * @FilePath: \xunku_official_website\src\store\index.ts
 * @IDE: Created by VScode.
 */
import { createStore } from "vuex";
import {
  UPDATE_TOKEN,
  UPDATE_HEADER_NAV_ACTIVE,
  UPDATE_SCROLL_TOP,
} from "./constant.mutation.types";

export interface VuexState {
  token: string;
  activeIndex: string /**当前活跃的导航项 */;
  scrollTop: number;
}

export default createStore({
  state() {
    return {
      token: "",
      activeIndex: "",
      scrollTop: 0,
    };
  },
  getters: {},
  mutations: {
    [UPDATE_TOKEN](state: VuexState, data: string) {
      return (state.token = data);
    },
    [UPDATE_HEADER_NAV_ACTIVE](state: VuexState, data: string) {
      return (state.activeIndex = data);
    },
    [UPDATE_SCROLL_TOP](state: VuexState) {
      return state.scrollTop++;
    },
  },
  actions: {},
  modules: {},
});
